package com.tencet.dao.impl;

import com.tencet.dao.RechargeDAO;
import com.tencet.entity.Recharge;
import com.tencet.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class RechargeDAOImpl implements RechargeDAO {

    private QueryRunner runner = new QueryRunner(JDBCUtils.getDataSource());
    @Override
    public int insert(Recharge recharge) {
        String sql = "insert into racharge values(?,?,?,?,?)";

        try {
            return runner.update(sql,recharge.getRecharge_id(),recharge.getBank_account(),recharge.getPhone_num(),recharge.getRecharge_time(),recharge.getRecharge_money());
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return -1;
    }

    @Override
    public List<Recharge> rechargeshow(String bankaccount) {
        QueryRunner queryRunner = new QueryRunner(JDBCUtils.getDataSource());

        String sql="select  recharge_id,bank_account,phone_num,recharge_time,recharge_money from racharge where bank_account=?";
        try {
            List<Recharge> query = queryRunner.query( sql, new BeanListHandler<Recharge>(Recharge.class),bankaccount);
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
